package com.blog.admin.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.blog.admin.service.UserService;

import com.alibaba.fastjson.JSONObject;
import com.blog.admin.pojo.auth.User;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;

@Controller
@RequestMapping(value = "/admin/user")
public class UserController {

	@Autowired
	private UserService UserService;

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	@RequiresPermissions("user:list")
	@ResponseBody
	public JSONObject submitLogin(@RequestParam("page") String pageNum, @RequestParam("limit") String pageSize, @RequestParam("username") String username) {

		PageMethod.startPage(Integer.valueOf(pageNum), Integer.valueOf(pageSize));
		List<User> userList = UserService.getUserList(username);

		PageInfo<User> pageInfo = new PageInfo<User>(userList);
		JSONObject jsObject = new JSONObject();
		jsObject.put("code", 0);
		jsObject.put("data", userList);
		jsObject.put("count", pageInfo.getTotal());
		return jsObject;
	}

	@RequestMapping(value = "/adduserPage", method = RequestMethod.GET)
	public String addUserPage() {
		return "pages/sysManager/adduserPage";
	}
}
